home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / soft / development / Macromedia RoboHelp X5 / RoboHelpOffice.exe / Data1.cab / _D902B9E18FB6416EB051FFC1BD2218AE < prev    next >
Encoding:
Text File  |  2003-07-07  |  3.6 KB  |  134 lines

  1. // HostHelper.cpp: implementation of the CHostHelper class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "stdafx.h"
  6. #include "HostHelper.h"
  7.  
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CTransform_ExportProject
  10. //Comment:
  11. //EngineHost IDispatch interface
  12. //
  13. //    interface IXmlHandlerHost : IDispatch
  14. //    {
  15. //        [id(1), helpstring("method InitNew")] HRESULT InitNew([in] IUnknown *pInternalHost);
  16. //        [id(2), helpstring("method NotifyMessage")] HRESULT NotifyMessage([in] BSTR bstrMsg);
  17. //        [id(3), helpstring("method NotifyError")] HRESULT NotifyError([in] BSTR bstrErrorMsg);
  18. //        [id(4), helpstring("method NotifyProgressTotal")] HRESULT NotifyProgressTotal([in] UINT nTotalStep);
  19. //        [id(5), helpstring("method NotifyProgress")] HRESULT NotifyProgress([in] UINT nCurrentStep);
  20. //        [id(6), helpstring("method GetProperty")] HRESULT GetProperty([in] BSTR bstrName, [out, retval] BSTR *pbstrValue);
  21. //    };
  22.  
  23. //////////////////////////////////////////////////////////////////////
  24. // Construction/Destruction
  25. //////////////////////////////////////////////////////////////////////
  26.  
  27. CHostHelper::CHostHelper(IDispatch *a_pDispatch)
  28. :m_psDispatch(a_pDispatch)
  29. {
  30.     ASSERT(a_pDispatch != NULL);
  31. }
  32.  
  33. CHostHelper::~CHostHelper()
  34. {
  35.  
  36. }
  37.  
  38. BOOL    CHostHelper::NotifyError(LPCTSTR a_pszError)
  39. {
  40.     DISPID nDispId = -1;
  41.     if ((CheckGetDispatchId("NotifyError",nDispId)) &&
  42.         (nDispId != -1))
  43.     {
  44.         CComVariant var = a_pszError;
  45.         HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
  46.         return (hr == S_OK)? TRUE: FALSE;
  47.     }
  48.     return FALSE;
  49. }
  50.  
  51. BOOL    CHostHelper::NotifyMessage(LPCTSTR a_pszMessage)
  52. {
  53.     DISPID nDispId = -1;
  54.     if ((CheckGetDispatchId("NotifyMessage",nDispId)) &&
  55.         (nDispId != -1))
  56.     {
  57.         CComVariant var = a_pszMessage;
  58.         HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
  59.         return (hr == S_OK)? TRUE: FALSE;
  60.     }
  61.     return FALSE;
  62. }
  63.  
  64. BOOL    CHostHelper::NotifyProgress(UINT a_nCurrentStep)
  65. {
  66.     DISPID nDispId = -1;
  67.     if ((CheckGetDispatchId("NotifyProgress",nDispId)) &&
  68.         (nDispId != -1))
  69.     {
  70.         CComVariant var = (LONG)a_nCurrentStep;
  71.         HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
  72.         return (hr == S_OK)? TRUE: FALSE;
  73.     }
  74.     return FALSE;
  75.  
  76. }
  77.  
  78. BOOL    CHostHelper::NotifyProgressTotal(UINT a_nTotalStep)
  79. {
  80.     DISPID nDispId = -1;
  81.     if ((CheckGetDispatchId("NotifyProgressTotal",nDispId)) &&
  82.         (nDispId != -1))
  83.     {
  84.         CComVariant var = (LONG)a_nTotalStep;
  85.         HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
  86.         return (hr == S_OK)? TRUE: FALSE;
  87.     }
  88.     return FALSE;
  89. }
  90.  
  91. BOOL    CHostHelper::GetProperty(LPCTSTR a_pszName, BSTR *a_pbstrValue)
  92. {
  93.     DISPID nDispId = -1;
  94.     if ((CheckGetDispatchId("GetProperty",nDispId)) &&
  95.         (nDispId != -1))
  96.     {
  97.         CComVariant var        = a_pszName;
  98.         CComVariant varRet;
  99.         HRESULT hr = m_psDispatch.Invoke1(nDispId,&var,&varRet);
  100.         if (hr == S_OK)
  101.         {
  102.             if (varRet.vt = VT_BSTR)
  103.             {
  104.                 CString strTmp = varRet.bstrVal;
  105.                 if (a_pbstrValue != NULL)
  106.                     *a_pbstrValue = strTmp.AllocSysString();
  107.             }
  108.         }
  109.         return (hr == S_OK)? TRUE: FALSE;
  110.     }
  111.     return FALSE;
  112. }
  113.  
  114. BOOL    CHostHelper::CheckGetDispatchId(LPCTSTR a_pszMethodName, DISPID &ar_nDispId)
  115. {
  116.     if (m_psDispatch != NULL)
  117.     {
  118.         //Check the host has IDispatch interface
  119.         CComPtr<IDispatch> psDispatch;
  120.         if ((m_psDispatch->QueryInterface(__uuidof(IDispatch),(void**)&psDispatch) == S_OK) &&
  121.             (psDispatch != NULL))
  122.         {
  123.             //find method dispatch id
  124.             CComBSTR bstrMethodName;
  125.             bstrMethodName = a_pszMethodName;
  126.             HRESULT hr = m_psDispatch.GetIDOfName(bstrMethodName, &ar_nDispId);
  127.             if (SUCCEEDED(hr))
  128.                 return TRUE;
  129.         }
  130.     }
  131.     return FALSE;
  132. }
  133.  
  134.